package com.itheima.reggie.servrce.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealDish;
import com.itheima.reggie.mapper.SetmealMapper;

import com.itheima.reggie.servrce.SetmealService;
import com.itheima.reggie.servrce.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal>implements SetmealService {
    @Autowired
    private  SetmealDishService setmealDishesService;
    @Override
    @Transactional
    public void saveWithDish(SetmealDto setmealDto) {
        //保存套餐的基本信息
        //save传递一个套餐的数据
        Setmeal setmeal=setmealDto;
        save(setmeal);
        Long setmealId=setmeal.getId();
        List<SetmealDish>setmealDishes=setmealDto.getSetmealDishes();
        for (SetmealDish setmealDish:setmealDishes){
            setmealDish.setDishId(setmealId);
        }
        setmealDishesService.saveBatch(setmealDishes);
    }
}
